package com.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class OutText {

	public static void main(String[] args){
		FileOutputStream out = null;
		FileInputStream input=null;
		byte[] a=new byte[1024];
		try {
			input=new FileInputStream("f:/2.jpg");
			 out=new FileOutputStream("e:/text5.jpg");
			int read=0;
			while ((read=input.read(a))>=0) {
				/*String string = new String(a);*/
				out.write(a, 0, read);
				System.out.println(read);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				out.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		/*File file=new File(".");
		copy(file);*/
	}
	static OutputStream out=null;
	static InputStream input=null;
	static byte[] bytes=new byte[1024];
	private static void copy(File file) {
		File[] listFiles = file.listFiles();
		for (File file2 : listFiles) {
			if (file2.isAbsolute()) {
				copy(file2);
			}
			if (file2.isFile()) {
				try {
					input=new FileInputStream(file2.getAbsolutePath());
					File files=new File("d:/tt/"+file2.getParent().substring(1));
					files.mkdirs();
				    files=new File(files,file2.getName());
				    int read=0;
					while ((read=input.read(bytes))>=0) {
						out.write(bytes, 0, read);
					}
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

}
